package com.huangj.pro2_h2pop;

import android.content.ContentResolver;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.huangj.huangjlibrary.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;


public class FirstMediaActivity extends BaseActivity implements MediaPlayer.OnCompletionListener {

    @BindView(R.id.iv_play)
    public ImageView iv_play;
    @BindView(R.id.vv_media)
    public VideoView vv_media;
    @BindView(R.id.btn_jump)
    public Button btn_jump;
    @BindView(R.id.iv_star)
    public ImageView iv_star;
    @BindView(R.id.tv_again)
    public TextView tv_again;

    @Override
    protected int getContentId() {
        return R.layout.firstmedia_layout;
    }

    @Override
    protected void init() {
//        Uri uri = Uri.parse("android:resource://com.huangj.pro2_h2pop/" + R.raw.media);
//        Log.d("print", "init: " + uri);
//        Uri uri2 = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.media);
//        Log.d("print", "init: " + uri2);
        vv_media.setOnCompletionListener(this);

    }

    @OnClick({R.id.iv_play, R.id.btn_jump,R.id.iv_star,R.id.tv_again})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_play:
                //显示跳过按钮；
                vv_media.setVisibility(View.VISIBLE);
                btn_jump.setVisibility(View.VISIBLE);
                //控制台；
                vv_media.setMediaController(new MediaController(this));
                //播放视屏；
                vv_media.setVideoURI(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/" + R.raw.media));
                vv_media.start();
                break;
            case R.id.btn_jump:
                starActivityForAnimation(new Intent(FirstMediaActivity.this, MainActivity.class),
                        R.anim.bottom_in,
                        R.anim.bottomout);
                finish();
                break;
            case R.id.iv_star:
                starActivityForAnimation(new Intent(FirstMediaActivity.this, MainActivity.class),
                        R.anim.bottom_in,
                        R.anim.bottomout);
                finish();
                break;
            case R.id.tv_again:
                vv_media.resume();
                break;
        }
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        //视频播放结束；
        iv_star.setVisibility(View.VISIBLE);
        tv_again.setVisibility(View.VISIBLE);
    }
}
